package io

import (
	"bufio"
	"com/study/util"
	"fmt"
	"io/ioutil"
	"os"
)

func File() {
	// 打开文件
	const filename = "D:/test.txt"
	file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0777)
	if err != nil {
		fmt.Println(err)
	}
	// 关闭文件
	defer file.Close()
	util.PrnType(file)

	readByte, _ := bufio.NewReader(file).ReadString('\n')
	util.PrnType(readByte)

	// 写入文件
	writer := bufio.NewWriter(file)
	writer.WriteString("hello worlds!!!")
	writer.Flush()

	ioutil.WriteFile(filename, []byte("hello world - 111"), 0666)

	readFile, _ := ioutil.ReadFile(filename)
	util.PrnType(string(readFile))
}
